//
//  WHFreedomFishCell.m
//  WHEasyBizLink
//
//  Created by ShengMeng on 9/26/25.
//

#import "WHFreedomFishCell.h"
#import "WHFreedomFishModel.h"
#import "UIView+Rounded.h"
#import "SDAutoLayout.h"
#import "myUILabel.h"

@interface WHFreedomFishCell ()

/** 图片  **/
@property(nonatomic,strong)UIImageView*micon;

/** 名称  **/
@property (nonatomic, weak)UILabel *nameLabel;

@property (nonatomic, weak)UILabel *payLabel;

@property (nonatomic, weak)UILabel *returnLabel;

@property (nonatomic, weak)UILabel *countLabel;

@property (nonatomic, weak)UIButton*moreBtn;

@property(nonatomic,strong)UIView*mbgView;

@end

@implementation WHFreedomFishCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        //1.创建控件
        [self createUIControls];
        //2.设置样式(布局)
        [self setUpUIControlsLayout];
    }
    return self;
}

-(void)createUIControls
{
    self.backgroundColor = [UIColor clearColor];
    _mbgView = [[UIView alloc] init];
    _mbgView.backgroundColor = [UIColor whiteColor];
    self.mbgView.userInteractionEnabled = YES;
    [self.contentView addSubview:self.mbgView];
   
    //[_mbgView setViewRoundedShadowWithRad:10 byRoundingCorners:UIRectCornerAllCorners];
    _micon = [[UIImageView alloc] init];
    
    [self.mbgView addSubview:self.micon];
   //[_micon setViewRoundedShadowWithRad:10 byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
    
    /**  应用名称  **/
    myUILabel*nameLabel = [[myUILabel alloc]init];
    nameLabel.font = [UIFont systemFontOfSize:18];
    //appNameLabel.textColor = [UIColor whiteColor];
    nameLabel.textColor = [UIColor colorWithHexString:@"#3C3C3C" alpha:1.0];
    nameLabel.numberOfLines = 2;
    [self.mbgView addSubview:nameLabel];
    nameLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    _nameLabel = nameLabel;
    
  
    UILabel*payLabel = [[UILabel alloc]init];
    payLabel.font = [UIFont systemFontOfSize:14];
    payLabel.textColor = [UIColor colorWithHexString:@"#767676" alpha:1.0];
    [self.mbgView addSubview:payLabel];
    payLabel.numberOfLines = 1;
    _payLabel= payLabel;
  
    
    UILabel*returnLabel = [[UILabel alloc]init];
    returnLabel.font = [UIFont systemFontOfSize:14];
    returnLabel.textColor = [UIColor colorWithHexString:@"#767676" alpha:1.0];
    [self.mbgView addSubview:returnLabel];
    returnLabel.numberOfLines = 1;
    _returnLabel= returnLabel;
    
    
    UILabel*countLabel = [[UILabel alloc]init];
    countLabel.font = [UIFont systemFontOfSize:14];
    countLabel.textColor = [UIColor colorWithHexString:@"#767676" alpha:1.0];
    [self.mbgView addSubview:countLabel];
    countLabel.numberOfLines = 1;
    _countLabel= countLabel;


    UIButton* moreBtn= [[UIButton alloc]init];
    moreBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [moreBtn setTitle:@"更多>" forState:UIControlStateNormal];
    [moreBtn setTitleColor:[UIColor colorWithHexString:@"#767676" alpha:1.0] forState:UIControlStateNormal];
    [self.mbgView addSubview:moreBtn];
    [moreBtn addTarget:self action:@selector(selecetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    _moreBtn= moreBtn;

    
}

- (void)setUpUIControlsLayout
{
    _mbgView
    .sd_layout
    .topSpaceToView(self.contentView, 5)
    .bottomSpaceToView(self.contentView, 10)
    .leftSpaceToView(self.contentView, 20)
    .rightSpaceToView(self.contentView,20);
    
    _micon
    .sd_layout
    .topSpaceToView(self.mbgView,10)
    .leftSpaceToView(self.mbgView,0)
    .widthIs(150)
    .heightIs(110);
    
    _nameLabel
    .sd_layout
    .topSpaceToView(self.mbgView,10)
    .leftSpaceToView(self.micon,10)
    .widthIs(ScreenW*2/3)
    .heightIs(30);
    
    _payLabel
    .sd_layout
    .topSpaceToView(self.nameLabel,10)
    .leftSpaceToView(self.micon,10)
    .widthIs(120)
    .heightIs(20);
    
    
    _returnLabel
    .sd_layout
    .topSpaceToView(self.payLabel,5)
    .leftSpaceToView(self.micon,10)
    .widthIs(120)
    .heightIs(20);
    
    _countLabel
    .sd_layout
    .topSpaceToView(self.returnLabel,5)
    .leftSpaceToView(self.micon,10)
    .rightSpaceToView(self.mbgView,10)
    .heightIs(20);
    
    _moreBtn.sd_layout
    .rightSpaceToView(self.mbgView,0)
    .centerYEqualToView(self.micon)
    .widthIs(40)
    .heightIs(20);

}

-(void)setModel:(WHFreedomFishModel *)model
{
    _model = model;
    
    _micon.image = [UIImage imageNamed:_model.image];
    _nameLabel.text     = _model.name;
    _payLabel.text =[NSString stringWithFormat:@"钓费: %@",_model.play];
    _returnLabel.text =[NSString stringWithFormat:@"回鱼: %@",_model.returnFish];
    _countLabel.text   =_model.count;
    
}

-(void)selecetBtnClick:(UIButton*)btn
{
    if ([_delegate respondsToSelector:@selector(wHFreedomFishCellBtnClick:)]) {
        [_delegate wHFreedomFishCellBtnClick:self.model];
    }

}


@end
